package edu.indiana.d2i.vmm.job;

public class SigiriHTRCJobExeContainer {
	public final String JOB_SUCCESS = "success";
	public final String JOB_FAIL = "fail";
	public final String JOB_RUNNING = "running";
	
	protected String exeScriptTempl = "$(%s) \n" + 
									"rc=$? \n" +
									"if [ \"$rc\" -ne 0 ]; then \n" +
									"touch fail.txt \n else \n" + 
									"touch success.txt \n fi";
	
	protected String queryScriptTempl = "if [ -e fail.txt ]; then \n" +
    									"echo \"fail\" \n" + 
    									"elif [ -e success.txt ]; then \n" +
    									"echo \"success\" \n else \n" +
    									"echo \"running\" \n fi"; 
	
	public String generateJobExeContainerScript(String cmdLine, String software) {
		String cmd = "";
		if (SigiriHTRCConstants.EXECUTABLE_TYPE_JAR.equals(software)) 
			cmd = "java -jar " + cmdLine;
		String script = String.format(exeScriptTempl, cmd);
		return script;
	}
	
	public String generateQueryJobScript() {
		return queryScriptTempl;
	}
}
